package view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.JButton;

import control.CtrlHospede;

import model.Hospede;

import java.awt.Font;
import java.util.ArrayList;
import java.util.List;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class JFrameListaCompletaHospede extends JFrame {

	private JPanel contentPane;
	private JTable tblHospedes;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					JFrameListaCompletaHospede frame = new JFrameListaCompletaHospede();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public JFrameListaCompletaHospede() {
		setTitle("Lista de H\u00F3spedes");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 615, 487);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		setResizable(false);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 11, 579, 428);
		contentPane.add(scrollPane);
		

		
		tblHospedes = new JTable();
		tblHospedes.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"Nome", "CPF", "RG", "Email", "Telefone", "Endere\u00E7o"
			}
		));
		scrollPane.setViewportView(tblHospedes);
		final DefaultTableModel model = (DefaultTableModel) tblHospedes.getModel();
		
		List<Hospede> listHospede = new ArrayList<>();
		CtrlHospede ctrlHospede = new CtrlHospede();
		listHospede = ctrlHospede.listaCompletaHospedes();
		for(Hospede cada: listHospede){
			Object[] objetoHospede = new Object[6];
			objetoHospede[0] = (""+cada.getNome());
			objetoHospede[1] = (""+cada.getCpf());
			objetoHospede[2] = (""+cada.getRg());
			objetoHospede[3] =	(""+cada.getEmail());	
			objetoHospede[4] = (""+cada.getTelefone());
			objetoHospede[5] = (""+cada.getEndereco());
			model.addRow(objetoHospede);
		}
	}
}
